﻿$(document).ready(function () {
    $('.button').click(function () {
        var n, e, s, c;
        var err = $('.msg p span').css('color', 'red');
        if ($('.name').val() == '') {
            err.html('Please enter your Name.....');
            $('.name').focus();
            return false;
        }
        else if ($('.email').val() == '') {
            err.html('Please enter your Email.....');
            $('.email').focus();
            return false;
        }
        else if ($('.email').val().match(/([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+/gi) == null) {
            err.html('Please check your Email.....');
            $('.email').focus();
            return false;
        }
        else if ($('.subject').val() == '') {
            err.html('Please enter your Subject.....');
            $('.subject').focus();
            return false;
        }
        else if ($('.tcontact').val() == '') {
            $('.msg p span').html('Please enter your Contact.....');
            $('.tcontact').focus();
            return false;
        }
        else {
            n = $('.name').val();
            e = $('.email').val();
            s = $('.subject').val();
            c = $('.tcontact').val();
        }
        $.ajax({
            type: "POST",
            url: "Process/update.asmx/Contact",
            data: "{'name':'" + n + "','email':'" + e + "', 'subject':'" + s + "', 'contact':'" + c + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                err.html('Sending..........');
                if (response.d == true) {
                    setTimeout(function () {
                        //$('.text_form').hide('slow');
                        $('.send').hide("slide", { direction: "left" }, 1000);
                        $('.sent').delay(200).show("slide", { direction: "right" }, 1000);
                        //$('.text_form').show('slow');
                    }, 2000);
                }
                else {
                    setTimeout(function () {
                        err.html('Error sending email, please try again later');
                    }, 2000);
                }
            },
            failure: function (msg) {
                alert('false')
            }
        });
        return false;
    });

    $('.comeback p span a').click(function () {
        $('.sent').hide("slide", { direction: "left" }, 1000);
        $('.send').delay(200).show("slide", { direction: "right" }, 1000);
        $('.name').val('');
        $('.email').val('');
        $('.subject').val('');
        $('.tcontact').val('');
        $('.msg p span').html('');
    });
});